home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Games Collection 1
/
software vault.zip
/
software vault
/
CDR10
/
SPX20.ZIP
/
SPX_DOC.ZIP
/
SPX_ES.DOC
< prev
next >
Wrap
Text File
|
1993-09-16
|
5KB
|
151 lines
{ SPX Library Version 2.0 Copyright 1993 Scott D. Ramsay }
SPX_ES allows a simplified method to load sprites in expanded memory.
Turbo Vision's Objects unit is required.
───────────────────────────────────────────────────────────────────────────
Before one would load sprites into main memory by doing the following:
var
sprites : array[1..MaxSprites] or pointer;
begin
loadVSP('myspr.vsp',sprites); { load the sprites }
fput(100,100,sprites[1]^,false); { display the 1st sprite on screen }
end;
This unit's method is very similar except first you have to create a global
expanded memory area to contain all the sprite data for the program.
const
maxSize = 200000; { about 200k of sprites need to be loaded }
var
emsGlobalmem : PEmsStack;
emsGlobalmem := CreateEmsStack(maxSize);
The function CreateEmsStack allocates expanded memory and returns a pointer
type for that area. If the area could not be allocated, then the function
returns NIL.
Once the memory area is created, you just load the sprites just like
before except the sprite array must be of type PEmsDyData.
var
sprites : array[1..MaxSprites] or PEmsDyData;
begin
StackLoadVSP('myspr.vsp',sprites,emsGlobalmem,false);
fput(100,100,vp(sprites[1])^,false); { display the 1st sprite on screen }
end;
StackLoadVSP takes two new arguments compared to LoadVSP.
You pass in the pointer to the expanded memory area and a boolean value.
If the boolean value is set to TRUE it forces StackLoadVSP to load the
sprites in regular heap space. This way you can automate the load:
StackLoadVSP('myspr.vsp',sprites,emsGlobalmem,(emsGlobalmem=nil));
If emsGlobalmem could not be allocated, then the sprites are loaded to
regular memory.
Notice in the fput procedure we call the function VP. The function Vp
accesses the expanded memory and returns an ACTUAL pointer to the sprite
data.
This pointer can point to the temporary buffer created by the unit. By
default the unit allocates 16k of memory as a temporary buffer. If you
want to change the buffer size, call the procedure ChangeTempBuffer.
The temporary buffer should be the same size or larger than the largest
sprite loaded.
At the end of your program you must call the DeleteEmsStack procedure to
deallocate your ems global memory. Since exiting a program does not free
expanded memory.
───────────────────────────────────────────────────────────────────────────
function CreateEmsStack(size:longint):PEmsStack;
Allocates ems global memory.
SIZE: Size of the memory to allocate
Returns: A pointer that describes the allocated memory area or NIL
if it could not allocate the memory
───────────────────────────────────────────────────────────────────────────
procedure DeleteEmsStack(var p:PEmsStack);
Deallocate ems global memory.
P: A pointer to the ems memory structure
At the end of your program you must call this procedure to
deallocate your ems global memory. Since exiting a program does not free
expanded memory.
───────────────────────────────────────────────────────────────────────────
function AddEmsStack(var p:PemsStack;var data;size:word):boolean;
Adds custom data to the ems memory area.
P: A pointer to the ems memory structure
DATA: Data to copy to ems memory
SIZE: Size of the data to copy
Returns TRUE if successful, else returns FALSE if memory area is
full or other error
Note:
The actual position of the data can be found by following:
ok := AddEmsStack(emsMem,data,dataSize);
if ok
then dataposition := emsMem^.flocator-dataSize;
───────────────────────────────────────────────────────────────────────────
function ReadEmsStack(var p:PemsStack;position:longint;var data;size:word):boolean;
Retreives data from ems memory area.
P: A pointer to the ems memory structure
POSITION: Offset to start reading
DATA: Data array to get the ems memory
SIZE: Size of the data to copy
Returns TRUE if successful
───────────────────────────────────────────────────────────────────────────
procedure ChangeTempBuffer(size:word);
Changes the temporary buffer
SIZE: Size to change temporary buffer
───────────────────────────────────────────────────────────────────────────
procedure StackLoadVSP(fn:string;var buff;var p:PEmsStack;loadlow:boolean);
Loads sprites to main memory or expanded memory
FN: VSP file name
BUFF: a PEmsDyData structure. Can be a single pointer or an array
of PEmsDyData.
P: A pointer to the ems memory structure to place the sprites
LOADLOW: Set to TRUE to force to load in main memory
Sets the variable vspcnt to the number of sprites loaded.
Note: When the allocated ems memory becomes full or can not be reached,
the rest of the sprites are loaded to main memory.
───────────────────────────────────────────────────────────────────────────
function vp(var p:PEmsDyData):pointer;
Returns a pointer to the data specfied by the PEmsDyData structure.
P: A pointer to the ems memory structure
───────────────────────────────────────────────────────────────────────────